<?php
namespace Components\Account\Backstage;

class Adapter {
	static private $instance = [];

	public function __construct($config = []) {
		
	}

	static private function newClassName($key, $class_name, $parameter) {
		if(isset(self::$instance[$key]) && !empty(self::$instance[$key])) {
			return self::$instance[$key];
		}

		$className = __NAMESPACE__ . '\\' . $class_name;
		if(!class_exists($className)) {
			throw new \Exception($className . ' is non-existent.');
		}

		return new $className();
	}

	static public function getValidationInstance($parameter = []) {
		if(isset(self::$instance['validation']) && !empty(self::$instance['validation'])) {
			return self::$instance['validation'];
		}

		return self::$instance['validation'] = new Validation();
	}

	static public function getModelInstance() {
		if(isset(self::$instance['model']) && !empty(self::$instance['model'])) {
			return self::$instance['model'];
		}

		return self::$instance['model'] = new Model();
	}

	static public function getServiceInstance($parameter = []) {
		if(isset(self::$instance['service']) && !empty(self::$instance['service'])) {
			return self::$instance['service'];
		}

		return self::$instance['service'] = new Service($parameter);
	}

	static public function getFilterInstance($parameter = []) {
		return self::newClassName('filter', 'Filter', $parameter);
	}

	static public function getAclInstance($parameter = []) {
		return self::newClassName('acl', 'Acl', $parameter);
	}
}
